package day20;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;


/**
 *
 * PrintWriterDemo.java
 * @author wangbiao<br/>
 *         email:785497344@qq.com
 * @description 熟悉字符打印流的API
 * @since 1.0.0
 * @date 2013-6-25下午11:08:08
 *
 */
public class PrintWriterDemo {

	public static void main(String[] args) {
		BufferedReader br = null;
		br = new BufferedReader(new InputStreamReader(System.in));
		// 打印到控制台
		PrintWriter pw = new PrintWriter(System.out);
		try {
			
			//打印到文件里
			pw = new PrintWriter(new File("print.txt"));
			pw = new PrintWriter("print.txt");
			//可以自动刷新
			pw = new PrintWriter(new FileWriter("print.txt"),true);
			String line = null;
			while ((line = br.readLine()) != null) {
				pw.println(line);
				pw.flush();
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (null != null) {
					br.close();
				}
				if (null != pw) {
					pw.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}
}
